package sy.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import sy.dao.AppEntryLogDaoI;
import sy.model.AppEntryLog;
@Repository("appEntryLogDao")
public class AppEntryLogDaoImpl implements AppEntryLogDaoI{
	private SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	
	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	private Session getCurrentSession(){
		return this.getSessionFactory().getCurrentSession();
	}

	@Override
	public void save(AppEntryLog appEntryLog) {
		// TODO Auto-generated method stub
		this.getCurrentSession().save(appEntryLog);
	}

	@Override
	public void update(AppEntryLog appEntryLog) {
		// TODO Auto-generated method stub
		this.getCurrentSession().saveOrUpdate(appEntryLog);
	}

	@Override
	public void deleteByIds(List<Integer> ids) {
		// TODO Auto-generated method stub
		String hql = "delete from AppEntryLog where id in :ids";
		Query query = this.getCurrentSession().createQuery(hql);
		query.setParameterList("ids", ids);
		query.executeUpdate();
	}

	@Override
	public List<AppEntryLog> list() {
		// TODO Auto-generated method stub
		return this.getCurrentSession().createQuery("from AppEntryLog order by openTime desc").list();
	}
}
